﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;

namespace VDPlayerDotNet
{

    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private const int playerCount = 4;
        private VDPlayer_WPF[] players = new VDPlayer_WPF[playerCount];
        public MainWindow()
        {
            InitializeComponent();
            Console.WriteLine("初始化输出函数:" + VDModule.SetVDModuleLog());
        }

        private void CloseWindow(object sender, EventArgs e)
        {
            for (int i = 0; i < playerCount; i++)
                if(players[i] != null)
                    players[i].Close();
        }

        private void Btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;
            string str = (string)btn.Content;
            int index = int.Parse(str[str.Length - 1].ToString());
            int i = index - 1;
            if(str.StartsWith("Create"))
            {
                btn.Content = "DeletePlayer" + index;
                if (players[i] != null)
                    throw new Exception("players[" + index + "] not is null");
                players[i] = new VDPlayer_WPF();
                players[i].Show();
            }
            else
            {
                btn.Content = "CreatePlayer" + index;
                players[i].Close();
                players[i] = null;
            }
        }
    }
}